package com.hq.ims.home.controller;

import com.hq.ims.data.entity.DataStaging;
import com.hq.ims.data.utils.LocalConstant;
import com.hq.ims.home.service.DataStagingBusService;
import com.hq.mybatis.base.page.RequestPage;
import com.hq.mybatis.base.page.ReturnPage;
import com.hq.utils.vo.ReturnVo;
import com.hq.web.annotations.GetJsonValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "数据暂存")
@RestController
@RequestMapping(value = LocalConstant.SYS_TYPE_PUBLIC_URL_PREFIX + "/data/staging")
public class DataStagingController {

    @Resource
    private DataStagingBusService dataStagingService;

    @ApiOperation(value = "生成数据暂存", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/add", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> add(
            @GetJsonValue(zh = "前端key") String key,
            @GetJsonValue(zh = "值") Object value
    ) {
        return dataStagingService.add(key, value);
    }

    @ApiOperation(value = "获取数据暂存分页列表", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/getStagingByPage", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<ReturnPage<DataStaging>> getStagingByPage(
            @RequestBody RequestPage requestPage,
            @GetJsonValue(required = false, zh = "前端key") String key,
            @GetJsonValue(required = false, zh = "公司id") String companyId,
            @GetJsonValue(required = false, zh = "项目id") String projectId
    ) {
        DataStaging dataStaging = new DataStaging();
        dataStaging.setKey(key);
        dataStaging.setCompanyId(companyId);
        dataStaging.setProjectId(projectId);
        return dataStagingService.getStagingByPage(requestPage, dataStaging);
    }

    @ApiOperation(value = "获取数据暂存详情", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/getStagingById", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Object> getStagingById(@GetJsonValue(zh = "数据暂存id") String stagingId) {
        return dataStagingService.getStagingById(stagingId);
    }

    @ApiOperation(value = "删除数据暂存详情", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/deleteStaging", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> deleteStaging(@GetJsonValue(zh = "数据暂存id") String stagingId) {
        return dataStagingService.deleteStaging(stagingId);
    }

    @ApiOperation(value = "使用数据暂存", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/userStaging", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> userStaging(@GetJsonValue(zh = "数据暂存id") String stagingId) {
        return dataStagingService.userStaging(stagingId);
    }
}
